package com.atguigui.leetcode1;

/**
 * 2379.得到 K 个黑块的最少涂色次数
 * Project: leetcode
 * Package: com.atguigui.leetcode1
 * Version: 1.0
 * <p>
 * Created by WJX on 2023/3/9 8:49
 */
public class P2379MinimumRecolorsToGetKConsecutiveBlackBlocks {
    public static void main(String[] args) {
        Solution solution = new P2379MinimumRecolorsToGetKConsecutiveBlackBlocks().new Solution();
        // TO TEST
    }

    class Solution {
        public int minimumRecolors(String blocks, int k) {

            int l = 0, r = 0, cnt = 0;
            while (r < k) {
                cnt += blocks.charAt(r) == 'W' ? 1 : 0;
                r++;
            }
            int res = cnt;
            while (r < blocks.length()) {
                cnt += blocks.charAt(r) == 'W' ? 1 : 0;
                cnt -= blocks.charAt(l) == 'W' ? 1 : 0;
                res = Math.min(res, cnt);
                l++;
                r++;
            }

            return res;
        }
    }
}
